package br.univas.vperiod.jowey.entities;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.OrderColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name="time_report")
public class TimeReport implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -6891540865258802285L;
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="idtime_report")
	private long idTimeReport;
	private String status;
	private int month;
	private int year;
	
	@Transient
	private String weekFrom;
	
	@Transient 
	private String weekTo;
	

	@OneToMany(fetch=FetchType.EAGER,mappedBy="timeReport", targetEntity=Week.class)
	@Fetch(FetchMode.SUBSELECT)
	@OrderBy("idWeek ASC")
	private List<Week> weeks;
	
	
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (idTimeReport ^ (idTimeReport >>> 32));
		result = prime * result + month;
		result = prime * result + ((status == null) ? 0 : status.hashCode());
		result = prime * result
				+ ((weekFrom == null) ? 0 : weekFrom.hashCode());
		result = prime * result + ((weekTo == null) ? 0 : weekTo.hashCode());
		result = prime * result + ((weeks == null) ? 0 : weeks.hashCode());
		result = prime * result + year;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TimeReport other = (TimeReport) obj;
		if (idTimeReport != other.idTimeReport)
			return false;
		if (month != other.month)
			return false;
		if (status == null) {
			if (other.status != null)
				return false;
		} else if (!status.equals(other.status))
			return false;
		if (weekFrom == null) {
			if (other.weekFrom != null)
				return false;
		} else if (!weekFrom.equals(other.weekFrom))
			return false;
		if (weekTo == null) {
			if (other.weekTo != null)
				return false;
		} else if (!weekTo.equals(other.weekTo))
			return false;
		if (weeks == null) {
			if (other.weeks != null)
				return false;
		} else if (!weeks.equals(other.weeks))
			return false;
		if (year != other.year)
			return false;
		return true;
	}
	
	public long getIdTimeReport() {
		return idTimeReport;
	}
	public void setIdTimeReport(long idTimeReport) {
		this.idTimeReport = idTimeReport;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public int getMonth() {
		return month;
	}
	public void setMonth(int month) {
		this.month = month;
	}
	public int getYear() {
		return year;
	}
	public void setYear(int year) {
		this.year = year;
	}
	public List<Week> getWeeks() {
		return weeks;
	}
	public void setWeeks(List<Week> weeks) {
		this.weeks = weeks;
	}
	public String getWeekFrom() {
		return weekFrom;
	}
	public void setWeekFrom(String weekFrom) {
		this.weekFrom = weekFrom;
	}
	public String getWeekTo() {
		return weekTo;
	}
	public void setWeekTo(String weekTo) {
		this.weekTo = weekTo;
	}
}
